package com.scau.phradmin.business.contents.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.scau.phradmin.common.util.PageDTO;
import com.scau.phradmin.domain.entity.Newhospital;
import com.scau.phradmin.domain.mapper.NewhospitalMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class HospitalServiceImpl {
    @Autowired
    private NewhospitalMapper hospitalMapper;

    /**
     * 查询所有新闻信息
     * @param pages
     * @return
     */
    public PageDTO<Newhospital> SelectAll(int pages){
        Page page=null;
        if(pages>0) {
            page=new Page(pages,10);
        }
        else{
            page=new Page(1,10);
        }
        List<Newhospital> list=hospitalMapper.queryAll(page);
        return PageDTO.valueOf(list,page);
    }

    /**
     * 通过id查询唯一新闻信息
     * @param id
     * @return
     */
    public Object SelectById(@RequestParam("id") Integer id){
        return hospitalMapper.queryOne(id);
    }

    @Transactional
    /**
     * 添加医院
     * @param user
     * @return
     */
    public boolean Add(Newhospital newhospital){
        return hospitalMapper.insert(newhospital) > 0;
    }
    /**
     * 更新医院
     */
    public boolean update(Newhospital newhospital) {
       return hospitalMapper.updateById(newhospital) > 0;
    }

    /**
     * 删除医院
     * @param id
     * @return
     */
    public boolean delete(Long id){
        return hospitalMapper.deleteById(id) > 0;
    }
}
